/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.udt.generator.core.rtgenerator.manager.dataconverter;

import com.inspur.edp.caf.generator.baseInfo.TypeInfo;
import com.inspur.edp.cef.designtime.api.IGspCommonDataType;
import com.inspur.edp.cef.generator.coreGenerator.base.mgrGenerator.ManagerGeneratorContext;
import com.inspur.edp.cef.generator.coreGenerator.base.serializer.changeser.dataType.SerGetTypesGenerator;
import com.inspur.edp.cef.spi.jsonser.abstractcefchange.AbstractCefDataSerItem;
import com.inspur.edp.cef.spi.jsonser.entity.AbstractEntitySerializerItem;
import com.inspur.edp.cef.spi.jsonser.valueobj.AbstractValueObjSerializer;
import java.util.ArrayList;
import org.eclipse.jdt.core.dom.ParameterizedType;

public class UdtDataGetTypesGenerator extends SerGetTypesGenerator {
    private static String varList = "list";

    public UdtDataGetTypesGenerator(IGspCommonDataType dataType, ManagerGeneratorContext mgrContext) {
        super(dataType,mgrContext);
    }

    @Override
    protected String getSerItemTypeName() {
        String typeName = "com.inspur.edp.cef.spi.jsonser.valueobj.ValueObjDataSerializerItem";
        addImport(typeName);
        return typeName;
    }
    protected TypeInfo getReturnType() {
        TypeInfo typeInfo = new TypeInfo(ArrayList.class.getTypeName());
        typeInfo.setIsParameterizedType(true);
        typeInfo.getArguments().add(new TypeInfo(AbstractValueObjSerializer.class));
        return typeInfo;
    }

    @Override
    protected void setListType(ParameterizedType parameterizedType) {
        parameterizedType.typeArguments().add((new TypeInfo(AbstractValueObjSerializer.class)).getType(this.ast));
    }

    //    protected Block buildMethodBody() {
//        Block block = this.ast.newBlock();
//        block.statements().add(this.createListDeclarationStatement());
//        List<ExpressionStatement> expressionStatementList = this.createAddListItemsStatement();
//        Iterator var3 = expressionStatementList.iterator();
//
//        while(var3.hasNext()) {
//            ExpressionStatement item = (ExpressionStatement)var3.next();
//            block.statements().add(item);
//        }
//
//        block.statements().add(this.createReturnStatement());
//        return block;
//    }
//
//    private VariableDeclarationStatement createListDeclarationStatement() {
//        VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
//        this.setListFragmentInfos(variableDeclarationFragment);
//        VariableDeclarationStatement variableDeclarationStatement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
//        this.setListStatementType(variableDeclarationStatement);
//        return variableDeclarationStatement;
//    }
//
//    private void setListStatementType(VariableDeclarationStatement variableDeclarationStatement) {
//        ParameterizedType parameterizedType = this.ast.newParameterizedType((new TypeInfo(ArrayList.class)).getType(this.ast));
//        parameterizedType.typeArguments().add((new TypeInfo(AbstractCefDataSerItem.class)).getType(this.ast));
//        this.addImport(AbstractCefDataSerItem.class.getTypeName());
//        variableDeclarationStatement.setType(parameterizedType);
//    }
//
//    private void setListFragmentInfos(VariableDeclarationFragment variableDeclarationFragment) {
//        variableDeclarationFragment.setName(this.ast.newSimpleName(varList));
//        ClassInstanceCreation classInstanceCreation = this.ast.newClassInstanceCreation();
//        ParameterizedType parameterizedType = this.ast.newParameterizedType((new TypeInfo(ArrayList.class)).getType(this.ast));
//        classInstanceCreation.setType(parameterizedType);
//        variableDeclarationFragment.setInitializer(classInstanceCreation);
//    }
//
//    private List<ExpressionStatement> createAddListItemsStatement() {
//        List<ExpressionStatement> list = new ArrayList();
//        Iterator var2 = this.serTypes.iterator();
//
//        while(var2.hasNext()) {
//            Class item = (Class)var2.next();
//            list.add(this.createAddListItemStatement(item));
//        }
//
//        return list;
//    }
//
//    private ExpressionStatement createAddListItemStatement(Class serType) {
//        MethodInvocation addMethodInvocation = this.ast.newMethodInvocation();
//        addMethodInvocation.setName(this.ast.newSimpleName("add"));
//        addMethodInvocation.setExpression(this.ast.newSimpleName("list"));
//        ClassInstanceCreation createItem = this.ast.newClassInstanceCreation();
//        createItem.setType(this.ast.newSimpleType(this.ast.newName(serType.getTypeName())));
//        addMethodInvocation.arguments().add(createItem);
//        return this.ast.newExpressionStatement(addMethodInvocation);
//    }
//
//    private ReturnStatement createReturnStatement() {
//        ReturnStatement returnStatement = this.ast.newReturnStatement();
//        returnStatement.setExpression(this.ast.newSimpleName("list"));
//        return returnStatement;
//    }
//
//    @Override
//    protected TypeInfo getReturnType() {
//        TypeInfo typeInfo = new TypeInfo(ArrayList.class.getTypeName());
//        typeInfo.setIsParameterizedType(true);
//        typeInfo.getArguments().add(new TypeInfo(AbstractCefDataSerItem.class));
//        return typeInfo;
//    }
}
